clear all
set more off
cd "/Users/yasenov/Dropbox (IPL)/mexican_repatriates2/"

use "data/aggregate_nber.dta"

************
************ SUMMARY STATS
************

label var pop30 "Population"
label var s_illit "Share Illiterate"
label var s_young "Share Age 18-40"
label var s_urban "Share Urban"
label var s_agric "Share Agriculture"
label var s_mf "Share Manufacturing"
label var extreme_phdi "Months Extreme Weather"
label var dustbowl "Dustbowl Intensity"
label var dmex "Mex Pop Drop"
label var rldf3329 "Retail sales growth 1929-33"
label var rldf3933 "Retail sales growth 1933-39"
label var miles_to_mex "Distance to Mexico"
label var miles_to_rr "Distance to Railway"
label var rail2 "Railway Presence"
label var mex_share10 "Mexican Share 1910"
label var pctdem "\% Democrat Votes"

global sumvars s_illit s_young s_urban s_agric s_mf extreme_phdi dustbowl dmex rldf3329 rldf3933 miles_to_mex miles_to_rr rail2 mex_share10 pctdem

eststo clear
eststo: estpost tabstat $sumvars, ///
	statistics(mean min max) columns(statistics)
	
esttab, cells("mean(fmt(%4.3f)) min(fmt(%4.3f)) max(fmt(%4.3f))") /// 
	nostar unstack nonote nonumber label
	
esttab using "results/sum_stats_agg.tex", ///
	cells("mean(fmt(%4.3f)) min(fmt(%4.3f)) max(fmt(%4.3f))") /// 
	nostar unstack nonote nonumber label replace

************
************ SCATTER PLOT
************

gen name2 = ""
replace name2 = name if mex_share10 > .5
replace name2 = name if dmex > .2
list name2 if name2 != ""
replace name2 = "" if name == "Jeff Davis, TX"
replace name2 = name if name == "Gila, AZ"
replace name2 = name if name == "Dimit, TX"
replace name2 = name if name == "Graham, AZ"
replace name2 = name if name == "Pima, AZ"
replace name2 = name if name == "Crockett, TX"
replace name2 = name if name == "Oklahoma, OK"
replace name2 = name if name == "Los Angeles, CA"
replace name2 = name if name == "Maricopa, AZ"
replace name2 = name if name == "Imperial, CA"
replace name2 = name if name == "El Paso, TX"

twoway (scatter dmex mex_share10 [aw=pop30], msymbol(circle_hollow)) ///
	(scatter dmex mex_share10, mlabel(name2) msymbol(i) mlabcolor(black) jitter(2)) ///
	(lfit dmex mex_share10 [aw=pop30], lcolor(black)), ///
	legend(off) ///
	xtitle("Mexican Share 1910") ///
	ytitle("Mexican Populaton Drop 1930-40") ///
	name(g1, replace)
drop name2

graph export "results/scatter.pdf", replace

************
************ REGRESSIONS ON SHARE LINKED
************

merge 1:1 county using "data/number_matched.dta"
keep if _merge == 3
drop _merge

gen share_linked = number_matched / pop30_native

global cnty_controls lnpop30 s_young s_agric s_mf s_urban s_illiterate dustbowl extreme_phdi pop_dens
global more_controls $cnty_controls rldf3329 c.rldf3329#c.rldf3329 miles_to_mex c.miles_to_mex#c.miles_to_mex c.miles_to_mex#c.rldf3329 aa relief loan death_rate rldf3933 c.rldf3933#c.rldf3933
global weight [aw = pop30]

label var mex_share10 "Enclave IV"
label var rail_interact "Railway IV"
label var close_to_rr_interact "Close to RR IV"
label var pctdem_interact "Dem Share IV"

eststo clear
eststo: areg share_linked mex_share10 $cnty_controls $weight, robust absorb(statefip)
qui estadd ysumm
estadd local bslncntrl "X"
estadd local morecntrls "" 
eststo: areg share_linked mex_share10 $more_controls $weight, robust absorb(statefip)
qui estadd ysumm
estadd local bslncntrl "X"
estadd local morecntrls "X" 

eststo: areg share_linked rail_interact rail2 $cnty_controls $weight, robust absorb(statefip)
qui estadd ysumm
estadd local bslncntrl "X"
estadd local morecntrls "" 
eststo: areg share_linked rail_interact rail2 $more_controls $weight, robust absorb(statefip)
qui estadd ysumm
estadd local bslncntrl "X"
estadd local morecntrls "X" 

eststo: areg share_linked close_to_rr_interact  close_to_rr $cnty_controls $weight, robust absorb(statefip)
qui estadd ysumm
estadd local bslncntrl "X"
estadd local morecntrls "" 
eststo: areg share_linked close_to_rr_interact close_to_rr $more_controls $weight, robust absorb(statefip)
qui estadd ysumm
estadd local bslncntrl "X"
estadd local morecntrls "X" 

esttab, ///
	keep(mex_share10 rail_interact close_to_rr_interact) ///
	b(3) se(3) label ///
	star(* .1 ** .05 *** .01) nonum nonotes ///
	mtitles("(1)" "(2)" "(3)" "(4)" "(5)" "(6)") ///
	stats(N ymean bslncntrl morecntrls, labels("N" "$\bar{Y}$" "Baseline Controls" "Full Controls"))

esttab using "results/share_linked.tex", ///
	keep(mex_share10 rail_interact close_to_rr_interact) ///
	b(3) se(3) label replace ///
	star(* .1 ** .05 *** .01) nonum nonotes ///
	mtitles("(1)" "(2)" "(3)" "(4)" "(5)" "(6)") ///
	stats(N ymean bslncntrl morecntrls, labels("N" "$\bar{Y}$" "Baseline Controls" "Full Controls") fmt(0 3))
	
